package com.meiqiongproperty.yiguanjia.fragment.home.yipension;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.meiqiongproperty.yiguanjia.R;
import com.meiqiongproperty.yiguanjia.databinding.PensionNewsListLayoutBinding;
import com.meiqiongproperty.yiguanjia.fragment.BaseFragment;
import com.meiqiongproperty.yiguanjia.fragment.home.adapter.OnItemClickListener;
import com.meiqiongproperty.yiguanjia.fragment.home.adapter.yiPensionAdapter.PensionNewsListAdapter;
import com.meiqiongproperty.yiguanjia.http.api.ApiService;
import com.meiqiongproperty.yiguanjia.http.interfaces.IHttpCallback;
import com.meiqiongproperty.yiguanjia.http.sendJsonModel.SendCommunityInfo;
import com.meiqiongproperty.yiguanjia.httpbean.TenementInformationInfo;
import com.meiqiongproperty.yiguanjia.utils.Utils;

/**
 * author: Administrator
 * date: 2017/7/12.
 * package:com.meiqiongproperty.yiguanjia.fragment.home.yipension
 */

public class PensionNewsListFragment extends BaseFragment {
    PensionNewsListLayoutBinding binding;
    PensionNewsListAdapter adapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding= DataBindingUtil.inflate(inflater, R.layout.pension_news_list_layout,container,false);
        binding.navigation.setTitle("养老资讯");
        binding.navigation.setLeftClick(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sendKeyBackEvent();
            }
        });

        pensionNewsList();

        LinearLayoutManager manager = new LinearLayoutManager(getActivity());
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        binding.recyclerPension.setLayoutManager(manager);
        return binding.getRoot();
    }

    /**
     * 养老资讯
     */
    public void pensionNewsList(){
        SendCommunityInfo send=new SendCommunityInfo();
        send.setToken(Utils.getToken(getActivity()));
        send.setRoomID(Utils.getRoomID(getActivity()));
        send.setCateId("3");
        send.setType("1");
        send.setPageSize("50");
        send.setPageNo("1");

        ApiService.getInfo(getActivity(), new IHttpCallback<TenementInformationInfo>() {
            @Override
            public void onNext(final TenementInformationInfo tenementInformationInfo) {
                adapter=new PensionNewsListAdapter(getActivity(),tenementInformationInfo.getInfo());
                binding.recyclerPension.setAdapter(adapter);

                adapter.setOnItemClickListener(new OnItemClickListener() {
                    @Override
                    public void onItemClick(View view, int position) {
                        toH5(tenementInformationInfo.getInfo().get(position).getUrl(),"资讯详情");
                    }
                });
            }

            @Override
            public void onError(int code, String message) {

            }
        }, Utils.getRequestBody(send));
    }
}
